#include <iostream>
#include <algorithm>
using namespace std;

typedef struct CITY
{
    int num;
    int fri;
    bool operator>(struct CITY c)
    {
        return num > c.num;
    }
    bool operator<(struct CITY c)
    {
        return num < c.num;
    }
} city;

const int N = 5010;

city c[N];
int n;
int f[N];
int res = 0;

int main()
{
    freopen("cin.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> c[i].num >> c[i].fri;
    sort(c + 1, c + 1 + n);
    for (int i = 1; i <= n; ++i)
    {
        f[i] = 1;
        for (int j = 1; j < i; ++j)
            if (c[i].fri > c[j].fri)
                f[i] = max(f[i], f[j] + 1);
    }
    for (int i = 1; i <= n; ++i)
        res = max(res, f[i]);
    cout << res;
    return 0;
}